package xin.clips.web.controller.gy;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import xin.clips.common.annotation.Log;
import xin.clips.common.enums.BusinessType;
import xin.clips.system.domain.gy.GyLocation;
import xin.clips.common.core.controller.BaseController;
import xin.clips.common.core.domain.AjaxResult;
import xin.clips.common.utils.poi.ExcelUtil;
import xin.clips.common.core.page.TableDataInfo;
import xin.clips.system.service.gy.IGyLocationService;

/**
 * 网点管理Controller
 *
 * @author clips
 * @date 2023-01-12
 */
@Controller
@RequestMapping("/gy/location")
public class GyLocationController extends BaseController
{
    private String prefix = "gy/location";

    @Autowired
    private IGyLocationService gyLocationService;

    @RequiresPermissions("gy:location:view")
    @GetMapping()
    public String location()
    {
        return prefix + "/location";
    }

    /**
     * 查询网点管理列表
     */
    @RequiresPermissions("gy:location:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GyLocation gyLocation)
    {
        startPage();
        List<GyLocation> list = gyLocationService.selectGyLocationList(gyLocation);
        return getDataTable(list);
    }

    /**
     * 导出网点管理列表
     */
    @RequiresPermissions("gy:location:export")
    @Log(title = "网点管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GyLocation gyLocation)
    {
        List<GyLocation> list = gyLocationService.selectGyLocationList(gyLocation);
        ExcelUtil<GyLocation> util = new ExcelUtil<GyLocation>(GyLocation.class);
        return util.exportExcel(list, "网点管理数据");
    }

    /**
     * 新增网点管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存网点管理
     */
    @RequiresPermissions("gy:location:add")
    @Log(title = "网点管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(GyLocation gyLocation)
    {
        return toAjax(gyLocationService.insertGyLocation(gyLocation));
    }

    /**
     * 修改网点管理
     */
    @RequiresPermissions("gy:location:edit")
    @GetMapping("/edit/{locationId}")
    public String edit(@PathVariable("locationId") String locationId, ModelMap mmap)
    {
        GyLocation gyLocation = gyLocationService.selectGyLocationByLocationId(locationId);
        mmap.put("gyLocation", gyLocation);
        return prefix + "/edit";
    }

    /**
     * 修改保存网点管理
     */
    @RequiresPermissions("gy:location:edit")
    @Log(title = "网点管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(GyLocation gyLocation)
    {
        return toAjax(gyLocationService.updateGyLocation(gyLocation));
    }

    /**
     * 删除网点管理
     */
    @RequiresPermissions("gy:location:remove")
    @Log(title = "网点管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(gyLocationService.deleteGyLocationByLocationIds(ids));
    }
}
